package com.ithema.notebook.processor;

import freemarker.template.Template;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

/**
 * Package: com.ithema.notebook.processor
 * Description：
 *
 * @author: huangjian
 * Date:  2020/10/18 17:13
 * Modified By:
 */
public abstract class AbstractFreemarkerProcessor implements Processor{
    protected abstract Object getModel(SourceNoteData sourceNoteData);
    protected abstract Template getTemplate() throws IOException;
    protected abstract Writer getWriter(SourceNoteData sourceNoteData) throws Exception;
    @Override
    public final void process(SourceNoteData sourceNoteData) throws Exception {
        Template template = getTemplate();
        Object model = getModel(sourceNoteData);
        Writer writer = getWriter(sourceNoteData);
        template.process(model,writer);
    }
}
